//
//  ViewControllerForClickRMCell.m
//  SeeTheWorld
//
//  Created by dllo on 16/1/28.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "ViewControllerForClickRMCell.h"
#import "PCH.pch"
#import <UIImageView+WebCache.h>


@interface ViewControllerForClickRMCell () <UIWebViewDelegate>

@property (nonatomic, retain)UIWebView *webView;
@property (nonatomic, retain)MBProgressHUD *HUD;
@property (nonatomic, retain)UIButton *buttonOfLeft;

@end

@implementation ViewControllerForClickRMCell

- (void)dealloc {
    self.webView.delegate = nil;
    [_buttonOfLeft release];
    [_HUD release];
    [_webView release];
    [super dealloc];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.buttonOfLeft = [UIButton buttonWithType:UIButtonTypeCustom];
    self.buttonOfLeft.frame = CGRectMake(5, 10, 30, 30);
    [self.buttonOfLeft addTarget:self action:@selector(fanHui:) forControlEvents:UIControlEventTouchUpInside];
    [self.buttonOfLeft setBackgroundImage:[UIImage imageNamed:@"iconfont-fanhui-2"] forState:UIControlStateNormal];
    UIBarButtonItem *bar = [[UIBarButtonItem alloc] initWithCustomView:self.buttonOfLeft];
    self.navigationItem.leftBarButtonItem = bar;
    [bar release];
    
    self.webView = [[UIWebView alloc] initWithFrame:[UIScreen mainScreen].bounds];
    NSURL *url = [NSURL URLWithString:self.url];
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    [self.view addSubview:self.webView];
    [self.webView loadRequest:request];
    [_webView release];
    
}

- (void)webViewDidFinishLoad:(UIWebView *)webView {
   
    [self.webView stringByEvaluatingJavaScriptFromString:@"document.getElementsByTagName('body')[0].style.webkitTextFillColor= '#C8C8C8'"];
    
    [self.webView stringByEvaluatingJavaScriptFromString:@"document.getElementsByTagName('body')[0].style.background='#2C2C2C'"];
    
    [self.webView stringByEvaluatingJavaScriptFromString:@"var hotel = document.getElementsByClassName('hotel-room');""for(i=0;i<hotel.length;i++){""hotel.item(i).style.background='#2C2C2C'""}"];

}

- (void)fanHui:(UIButton *)bu {
    
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)viewWillAppear:(BOOL)animated {
    
    /** 初始化进度框, 置于当前的View中 */
    self.HUD = [[MBProgressHUD alloc] initWithView:self.view];
    
    [self.view addSubview:self.HUD];
    
    /** 如果设置此属性则当前的view置于后台 */
    self.HUD.dimBackground = YES;
    
    self.HUD.labelText = @"请稍等";
    
    /** 显示对话框 */
    [self.HUD showAnimated:YES whileExecutingBlock:^{
        
        /** 对话框显示时需要执行的操作 */
        sleep(1);
        
    } completionBlock:^{
        
        /** 操作执行完后取消对话框 */
        [self.HUD removeFromSuperview];
        
        self.HUD = nil;
        
    }];
    
    if ([[NSUserDefaults standardUserDefaults] boolForKey:@"夜间模式"]) {
        
        [DKNightVersionManager nightFalling];
        
        self.webView.delegate = self;
        
    } else {
        
        [DKNightVersionManager dawnComing];
    }
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
